package com.dongjiantong.common.web.util;

import com.dongjiantong.common.web.model.BaseUser;

/**
 * @author cao
 * @create 2017-12-05 上午11:59
 **/
public final class UserUtil {
    private static ThreadLocal<BaseUser> user = new ThreadLocal<>();

    public static void putCurrentUser(BaseUser baseUser) {
        user.set(baseUser);
    }

    public static <T extends BaseUser> T getCurrentUser() {
        return (T)user.get();
    }

    public static void clearCurrentUser() {
        user.remove();
    }

    public static Long getUserId() {
        BaseUser baseUser = user.get();
        if (null != baseUser) {
            return baseUser.getId();
        }
        return null;
    }
}
